package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"
	"go-zero-mall/app/admin/model"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type AdminRoleDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAdminRoleDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminRoleDetailLogic {
	return &AdminRoleDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 管理员-角色查看
func (l *AdminRoleDetailLogic) AdminRoleDetail(in *pd.UmsAdminRoleDetailReq) (*pd.UmsAdminRoleDetailResp, error) {
	d, err := l.svcCtx.UmsAdminRoleRelationModel.FindOne(l.ctx, in.Id)
	if err != nil && err != model.ErrNotFound {
		return nil, err
	}
	var data pd.UmsAdminRoleDetailResp
	copier.Copy(&data, d)
	return &data, nil
}
